package searcher;

import java.util.List;

import util.CommonFactory;
import util.cache.normal.INormalCachable;
import algorithm.text.wordsegment.WordSegmentor;

/**
 * 用户请求，保存了查询词，并且实现了ICachable接口，可以用作缓存的Key
 * @author aleck
 *
 */
public class Request implements INormalCachable {
	public static final int WS_ALGORITHM = WordSegmentor.ALGORITHM_DYNAMIC;
	public static final WordSegmentor ws = CommonFactory.getWordSegmentor();

	private String originalQuery;
	private List<String> parsedQuery;

	public Request(String originalQuery) {
		this.originalQuery = originalQuery;
		parsedQuery = ws.segmentToWords(originalQuery, 0, originalQuery.length(), WS_ALGORITHM);
	}
	
	@Override
	public int getHashCode() {
		return originalQuery.hashCode();
	}

	@Override
	public boolean isEquivalentTo(Object o) {
		if (o == null || !(o instanceof Request))
			return false;
		Request that = (Request) o;
		return originalQuery.equals(that.originalQuery);
	}

	public String getOriginalQuery() {
		return originalQuery;
	}

	public void setOriginalQuery(String originalQuery) {
		this.originalQuery = originalQuery;
	}

	public List<String> getParsedQuery() {
		return parsedQuery;
	}

	public void setParsedQuery(List<String> parsedQuery) {
		this.parsedQuery = parsedQuery;
	}

}
